package com.googlecode.antilopebpm.definition;

import java.net.URL;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.googlecode.antilopebpm.AntilopeTestSupport;

public abstract class XMLTestSupport extends AntilopeTestSupport {
	protected static final Logger logger = LoggerFactory
			.getLogger(XMLTestSupport.class);
	protected JAXBContext jaxbContext;

	protected Object parseUri(String uri) throws JAXBException {
		Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
		URL resource = getClass().getResource(uri);
		assertNotNull("Cannot find resource on the classpath: " + uri, resource);
		Object value = unmarshaller.unmarshal(resource);
		return value;
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		jaxbContext = JAXBContext
				.newInstance("com.googlecode.antilopebpm.definition");
	}
}
